import { ElMessage } from 'element-plus'
import { getAllTypes as allTypesAPI } from '../../api/type'
import router from '../../router/index'
export default {
    namespaced: true,
    state: () => ({
        allTypes: [],
    }),
    mutations: {
        saveTypes(state:any, data:[]) {
            state.allTypes = data
        }
    },
    actions: {
        getAllTypes({ commit }: any, data: any) {
            return new Promise<void>((resolve, reject) => {
                allTypesAPI().then((res: any) => {
                    if(res.code == 200) {
                        commit('saveTypes', res.data)
                        window.sessionStorage.setItem('allTypes', JSON.stringify(res.data))
                        console.log("获取到的电影类型",res.data);
                        resolve(res)
                    }else{
                        ElMessage.error(res.msg)
                        reject(res)
                    }
                })
                .catch((err: any) => reject(err))
            })
       },
    }
}